home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks97
/
WarriorsProgress.sit
/
Warrior’s Progress
/
source code
/
Source
/
Libraries
/
Heap
/
Heap.h
< prev
next >
Wrap
Text File
|
1997-06-28
|
1KB
|
58 lines
// Heap.h
#ifndef Heap_h
#define Heap_h
#ifndef Integers_h
#include "Integers.h"
#endif
#ifndef Assert_h
#include "Assert.h"
#endif
template < class Element > class HeapLink;
template < class Element >
class Heap
{
typedef Element ElementType;
typedef HeapLink< Element > LinkType;
typedef Heap< Element > HeapType;
typedef bool (ElementType::*Comparator)( const Element& ) const;
private:
uint32 nodeCount;
LinkType *top;
const Comparator below;
LinkType** SubHeap( uint32 path );
LinkType& RemoveLast();
void SinkNode( LinkType**& subHeap, LinkType*& newNode );
void Percolate( LinkType** subHeap );
void Validate( LinkType& node, uint32 level ) const;
// not implemented:
Heap( const Heap& );
void operator=( const Heap& );
public:
Heap( Comparator below ); // Typically operator<=( const Element& ) const
~Heap();
Comparator Below() const { return below; }
bool IsEmpty() const { return top == 0; }
LinkType& Top() const { Assert( top != 0 ); return *top; }
LinkType& Pop();
void Add( LinkType& );
void Remove( LinkType& );
void Validate() const; // Checks a set of assertions
};
#endif